﻿namespace ClassyBlog.Infrastructure
{
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;

    public class FileSystem : IFileSystem
    {
        public IEnumerable<string> Files(
            string path, string searchPattern, bool includeSubdirectory)
        {
            var directory = new DirectoryInfo(path);

            var option = includeSubdirectory ?
                         SearchOption.AllDirectories :
                         SearchOption.TopDirectoryOnly;

            var paths = !directory.Exists ?
                        Enumerable.Empty<string>() :
                        directory.GetFiles(searchPattern, option)
                                 .Select(f => f.FullName);

            return paths;
        }

        public bool FileExists(string path)
        {
            var result = File.Exists(path);

            return result;
        }

        public string ReadAll(string path)
        {
            var result = File.ReadAllText(path);

            return result;
        }
    }
}